//
//  ScaleDragGridAppDelegate.m
//  ScaleDragGrid
//
//  Created by Basuke on 08/03/26.
//  Copyright Basuke's 2008. All rights reserved.
//

#import "ScaleDragGridAppDelegate.h"
#import "MyView.h"
#import "Console.h"

@implementation ScaleDragGridAppDelegate

@synthesize window;
@synthesize contentView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {	
	// Create window
	self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    
	self.contentView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)] autorelease];
	
	MyView *myView = [[[MyView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
	myView.name = @"MyView 1";
	[self.contentView addSubview:myView];
    
	myView = [[[MyView alloc] initWithFrame:CGRectMake(500, 0, 500, 500)] autorelease];
	myView.name = @"MyView 2";
	[self.contentView addSubview:myView];
	
	myView = [[[MyView alloc] initWithFrame:CGRectMake(500, 500, 500, 500)] autorelease];
	myView.name = @"MyView 3";
	[self.contentView addSubview:myView];
	
	myView = [[[MyView alloc] initWithFrame:CGRectMake(0, 500, 500, 500)] autorelease];
	myView.name = @"MyView 4";
	[self.contentView addSubview:myView];
	
	// Set up content view
	UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
	
	scrollView.contentSize = [self.contentView frame].size;
	[scrollView addSubview:self.contentView];
	
	scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
	scrollView.minimumZoomScale = 0.25;
	scrollView.maximumZoomScale = 4;
	scrollView.delegate = self;
	
	[window addSubview:[scrollView autorelease]];
    
	// Show window
	[window makeKeyAndVisible];
}

- (void)dealloc {
	[contentView release];
	[window release];
	[super dealloc];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//	NSLog(@"scrollViewDidScroll:(UIScrollView *)scrollView");
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
	NSLog(@"scrollViewWillBeginDragging:(UIScrollView *)scrollView");
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
	NSLog(@"scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate");
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
	NSLog(@"scrollViewWillBeginDecelerating:(UIScrollView *)scrollView");
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
	NSLog(@"scrollViewDidEndDecelerating:(UIScrollView *)scrollView");
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
	NSLog(@"scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView");
}

- (UIView *)scrollViewWillBeginZooming:(UIScrollView *)scrollView {
	NSLog(@"scrollViewWillBeginZooming:(UIScrollView *)scrollView");
	[[Console sharedConsole] dumpViewHierarchy:scrollView];
	return self.contentView;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
	NSLog(@")scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:%f", scale);
	[[Console sharedConsole] dumpViewHierarchy:scrollView];
	[view setNeedsDisplay];
}

@end
